package com.spark.check.widget

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.spark.check.R
import com.spark.check.model.ChargePeopleModel

class ItemChargeTaskView
(context: Context, attrs: AttributeSet?, defStyle: Int) : LinearLayout(context, attrs, defStyle) {
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context) : this(context, null, 0)

    init {
        orientation = VERTICAL
    }

    fun bind(datas: MutableList<ChargePeopleModel.Task>) {
        datas.forEach {
            val child = ItemChargeItemTaskView(context)
            child.bind(it)
            addView(child)
        }
        invalidate()
    }

}

class ItemChargeItemTaskView(context: Context, attrs: AttributeSet?, defStyle: Int) : RelativeLayout(context, attrs, defStyle) {
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context) : this(context, null, 0)

    private var tvTitle: TextView = rootView.findViewById(R.id.tv_title_person)
    private var tvContent: TextView = rootView.findViewById(R.id.tv_content)

    override fun getRootView(): View {
        return LayoutInflater.from(context).inflate(R.layout.item_charge_people_task, this)
    }

    @SuppressLint("SetTextI18n")
    fun bind(data: ChargePeopleModel.Task) {
        tvTitle.text = "${data.serialno} ${data.chargepeople}"
        tvContent.text = data.content
    }


}